Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Data Classes to Model API Responses #203

Merged
merged 5 commits into from
Dec 23, 2024

Conversation

jm-rivera
Copy link
Contributor

@jm-rivera jm-rivera commented Dec 4, 2024

Note:
Previous PR in the stack: #202
Next PR in the stack #204


This PR implements dataclasses to model API responses from all endpoints. These data classes represent various entities in the Data Commons knowledge graph. Dan's comments on the design document provide more details about the rationale.

Data Classes

  • datacommons_client/models/node.py: Added Node, NodeGroup, Arcs, and Properties data classes to represent nodes, groups of nodes, arcs, and properties in the Data Commons knowledge graph.

  • datacommons_client/models/observation.py: Added Observation, OrderedFacets, Variable, and Facet data classes to represent observations, ordered facets, variables, and facets in the Data Commons knowledge graph.

  • datacommons_client/models/resolve.py: Added Candidate and Entity data classes to represent candidates and entities in the resolution response.

  • datacommons_client/models/sparql.py: Added Cell and Row data classes to represent cells and rows in a SPARQL query response. Note that the sparql endpoint does not (currently) work for custom instances.

Unit Tests

In general, the tests for these classes are just making sure that the objects (especially objects that incorporate other objects) are built consistently and correctly. We avoid testing any basic python functionality.

Copy link

google-cla bot commented Dec 4, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@beets
Copy link
Contributor

beets commented Dec 6, 2024

/gcbrun

Copy link

@dwnoble dwnoble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Jorge! Looking great.

datacommons_client/models/observation.py Show resolved Hide resolved
Adds:
- A Node dataclass which models an individual node (with dcid, name, etc)
- A NodeGroup dataclass which represents a list of Node objects
- An Arcs dataclass, which represents arcs (with a label and containing NodeGroups)
- A Properties dataclass which represents a list of Properties
Adds:
- An Observation dataclass which models an individual observation (date, value)
- An OrderedFacets dataclass which models the 'ordered facets' of observations
- A Variable dataclass which represents a variable data (grouped by entity)
- A Facet class which represents the metadata for a facet
Adds:
- A candidate dataclass to model candidates in the response (with dcid and dominanType)
- An Entity dataclass to model entities with their resolution candidates
Adds:
- A Cell dataclass to model a single cell in a row
- A Row modelling a row with cells.
Adds tests for node, observation, resolve and sparql models.
@jm-rivera jm-rivera merged commit 63a78f9 into datacommonsorg:master Dec 23, 2024
2 checks passed
@jm-rivera jm-rivera deleted the 14-util-models branch December 23, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants